/**
 * @param {number[]} nums
 * @return {number[][]}
 */
function backtrace(calback) {
    let fn = function(nums, newArr) {
        if(nums.length == 0) {
            calback(newArr)
            // console.log(output);
            return
        }
        for(let i = 0; i < nums.length; i++) {
            let newNums = newArr.slice();
            let newInNums = nums.slice();
            newNums.push(nums[i]);
            newInNums.splice(i, 1);
            fn(newInNums, newNums);
        }
    }
    return fn;
}
const permute = function(nums) {
    let res = []
    backtrace((arr)=>{
        res.push(arr)
    })(nums, []);
    return res;
};
module.exports = permute;